{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "354eeff5",
   "metadata": {},
   "source": [
    "# 赋值与Copy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3b9e5d7",
   "metadata": {},
   "source": [
    "## 赋值(=) <=> copy?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e64de9c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_id = [101,102,103,104,105,106]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c5b2000a",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [101, 102, 103, 104, 105, 106] \n",
      " stu_id_matedata: [101, 102, 103, 104, 105, 106]\n"
     ]
    }
   ],
   "source": [
    "# 实验一：赋值 用pop来检验matedata的效果\n",
    "stu_id_matedata = stu_id\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6fcceb9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [101, 103, 104, 105, 106] \n",
      " stu_id_matedata: [101, 102, 103, 104, 105, 106]\n"
     ]
    }
   ],
   "source": [
    "# 实验2 copy()，用pop来检验，看看mate与copy的区别\n",
    "stu_id_matedata = stu_id.copy()\n",
    "stu_id.pop(1)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)\n",
    "# 总结copy是完全的不受影响的真正的复制行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2800b5ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [101, 104, 105, 106] \n",
      " stu_id_matedata: [101, 103, 104, 105, 106]\n"
     ]
    }
   ],
   "source": [
    "# 实验3 切片实现复制\n",
    "stu_id_matedata = stu_id[:]\n",
    "stu_id.pop(1)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "419ab368",
   "metadata": {},
   "source": [
    "# 列表的高级方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "361933f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_id = [101,102,103,104,105,106]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "23bb5353",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何取出所有位置10001的index？\n",
    "for i in stu_id:\n",
    "    # 循环遍历stu_id的所有内容\n",
    "    if i == 101:\n",
    "         # 判断如果元素为66的时候,怎么取出索引值呢？\n",
    "        print(stu_id.index(101))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dfeaf8c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 枚举:因为list其实不仅有values值，还有index索引，但for循环主要循环遍\n",
    "# 历其值，不遍历索引。因此，有了枚举的方法，同时遍历两者"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0e75f8d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 枚举 enumerate()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d06e5734",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 101\n",
      "我们想要删除pop()的值： [0]\n"
     ]
    }
   ],
   "source": [
    "pop_values_list = []\n",
    "# append方法经常用于新建列表\n",
    "for index,item in enumerate(stu_id):\n",
    "    # print(index,item)\n",
    "    if item == 101:\n",
    "        print(index,item)\n",
    "        pop_values_list.append(index)\n",
    "print(\"我们想要删除pop()的值：\",pop_values_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6be5b8a2",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "72400816",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b99d605d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5a01205f",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77fe1233",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e140b17c",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f956b8f",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
